package com.ponhu.ea2.goodsCenter.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ponhu.ea2.entity.PhCategory;
import com.ponhu.ea2.goodsCenter.provider.mapper.PhCategoryMapper;
import com.ponhu.ea2.goodsCenter.provider.service.PhCategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商品类目表  服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-10-14
 */
@Service
public class PhCategoryServiceImpl
        extends ServiceImpl<PhCategoryMapper, PhCategory>
        implements PhCategoryService {

    /**
     * 获取指定分级和父级类目ID的全部类目集合
     *
     * @param level
     * @param parentIds
     * @return
     */
    @Override
    public List<PhCategory> getPhCategorysByLevel(Integer level, Long parentIds, Boolean isAll) {

        LambdaQueryWrapper<PhCategory> queryWrapper = Wrappers
                .lambdaQuery(PhCategory.class);

        if (ObjectUtils.isNotEmpty(level))
            queryWrapper.eq(PhCategory::getLevel, level);

        if (parentIds != null)
            queryWrapper.in(PhCategory::getParentId, parentIds);

        if (BooleanUtils.isFalse(isAll))
            queryWrapper.eq(PhCategory::getStatus, 1);

        return list(queryWrapper);
    }
}
